package com.lzx.guanchajava.adapter.topicListAdapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import androidx.databinding.DataBindingUtil
import androidx.databinding.library.baseAdapters.BR
import androidx.recyclerview.widget.RecyclerView
import com.lzx.guanchajava.pojo.bean.topicList.TopicItem
import com.lzx.guanchajava.pojo.bean.postTopicList.Data
import com.lzx.guanchajava.R
import com.lzx.guanchajava.adapter.BaseRecyclerViewAdapter
import com.lzx.guanchajava.databinding.ItemTopicListBinding
import com.lzx.guanchajava.view.widget.UrlImageView
import org.jetbrains.anko.sdk27.coroutines.onClick

class PostTopicListAdapter : BaseRecyclerViewAdapter<Data>() {

    lateinit var onClickListener : OnClickListener

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
            TopicHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.context), R.layout.item_topic_list, parent, false))

    override fun getItemCount(): Int = data.size


    interface OnClickListener {
        fun onClick(id: String)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val d = data[position]
        val topic = TopicItem.fromData(d)
        (holder as TopicHolder).binding.data = topic
    }
}